import type { ConsultType } from '@/enums'
import type { ConsultIllness, PartialConsult } from '@/types/consult'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useConsultStore = defineStore(
  'cp-consult',
  () => {
    const consult = ref<PartialConsult>({})
    // 设置问诊类型
    const setType = (type: ConsultType) => (consult.value.type = type)
    // 记录问诊级别 0 和 1
    const setIllnessType = (type: 0 | 1) => {
      consult.value.illnessType = type
    }
    // 记录病情
    const setIllness = (illness: ConsultIllness) => {
      consult.value.illnessDesc = illness.illnessDesc
      consult.value.illnessTime = illness.illnessTime
      consult.value.consultFlag = illness.consultFlag
      consult.value.pictures = illness.pictures
    }
    // 选择科室
    const setDep = (depId: string) => (consult.value.depId = depId)
    // 记录病人id
    const setPatient = (patientId: string) => {
      consult.value.patientId = patientId
    }
    // 记录优惠卷
    const setCoupon = (couponId: string) => {
      consult.value.couponId = couponId
    }
    // 清除患者信息
    const clear = () => {
      consult.value = {}
    }
    return {
      consult,
      setType,
      setIllnessType,
      setDep,
      setIllness,
      setPatient,
      setCoupon,
      clear
    }
  },
  //配置我们的持久化插件
  {
    persist: true
  }
)
